package com.asjy.controller;

import com.asjy.po.CategoryExt;
import com.asjy.po.Product;
import com.asjy.po.ProductPageBean;
import com.asjy.service.CategoryService;
import com.asjy.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: lilinlin
 * @Date: 2021/4/12
 * @Description: com.asjy.controller
 * @version: 1.0
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    @Resource
    private ProductService productService;
    @RequestMapping("/toProductList")
    public  String toProductList(ProductPageBean productPageBean,Model model){
        ProductPageBean productByPageBean = productService.getProductByPageBean(productPageBean);
        List<Product> isHotProduct = productService.getIsHotProduct(productPageBean);
        int[] pages = productByPageBean.getPages();
        for (int i = 0; i <pages.length ; i++) {
            System.out.println(pages[i]+"..");
        }

        model.addAttribute("productByPageBean",productByPageBean);
        model.addAttribute("isHotProduct",isHotProduct);
        return "productList";

    }

    @RequestMapping("/toProductView")
    public ModelAndView toProductView(Integer pId){
        //ModelAndView属于Model和ModelMap的结合体，里面有成员ModelMap
        Product product = productService.getProductById(pId);
        ModelAndView mv = new ModelAndView();
        mv.addObject("product",product);
        mv.setViewName("productView");
        return mv;
    }
}